API: icontheme: Add 2 new GtkIconLookupFlags
authorBenjamin Otte <otte@redhat.com>
Sat, 10 May 2014 13:35:12 +0000 (15:35 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 14 May 2014 02:28:34 +0000 (04:28 +0200)
GTK_ICON_LOOKUP_FORCE_REGULAR and GTK_ICON_LOOKUP_FORCE_SYMBOLIC can be
used to force a regular or symbolic icon to be loaded, even if the icon
names specify a different version.

This is intended to support the CSS property -gtk-icon-style.

gtk/gtkicontheme.c
gtk/gtkicontheme.h

index 1d9209ac80c2a2d8b6c48ff8764e243432fe5fd7..8bf1062fd5ffadaf019c19da18e36069e4fc0640 100644 (file)
@@ -1592,11 +1592,11 @@ symbolic_pixbuf_cache_free (SymbolicPixbufCache *cache)
 }
 
 static GtkIconInfo *
-choose_icon (GtkIconTheme       *icon_theme,
-            const gchar        *icon_names[],
-            gint                size,
-             gint                scale,
-            GtkIconLookupFlags  flags)
+real_choose_icon (GtkIconTheme       *icon_theme,
+                  const gchar        *icon_names[],
+                  gint                size,
+                  gint                scale,
+                  GtkIconLookupFlags  flags)
 {
   GtkIconThemePrivate *priv;
   GList *l;
@@ -1794,6 +1794,65 @@ choose_icon (GtkIconTheme       *icon_theme,
   return icon_info;
 }
 
+static GtkIconInfo *
+choose_icon (GtkIconTheme       *icon_theme,
+             const gchar        *icon_names[],
+             gint                size,
+             gint                scale,
+             GtkIconLookupFlags  flags)
+{
+  gboolean has_regular = FALSE, has_symbolic = FALSE;
+  GtkIconInfo *icon_info;
+  gchar **new_names;
+  guint i;
+
+  for (i = 0; icon_names[i]; i++)
+    {
+      if (g_str_has_suffix (icon_names[i], "-symbolic"))
+        has_symbolic = TRUE;
+      else
+        has_regular = TRUE;
+    }
+
+  if ((flags & GTK_ICON_LOOKUP_FORCE_REGULAR) && has_symbolic)
+    {
+      new_names = g_new0 (gchar *, i + 1);
+      for (i = 0; icon_names[i]; i++)
+        {
+          if (g_str_has_suffix (icon_names[i], "-symbolic"))
+            new_names[i] = g_strndup (icon_names[i], strlen (icon_names[i]) - strlen ("-symbolic"));
+          else
+            new_names[i] = g_strdup (icon_names[i]);
+        }
+    }
+  else if ((flags & GTK_ICON_LOOKUP_FORCE_SYMBOLIC) && has_regular)
+    {
+      new_names = g_new0 (gchar *, i + 1);
+      for (i = 0; icon_names[i]; i++)
+        {
+          if (!g_str_has_suffix (icon_names[i], "-symbolic"))
+            new_names[i] = g_strconcat (icon_names[i], "-symbolic", NULL);
+          else
+            new_names[i] = g_strdup (icon_names[i]);
+        }
+    }
+  else
+    {
+      new_names = NULL;
+    }
+
+  icon_info = real_choose_icon (icon_theme,
+                                new_names ? (const gchar **) new_names : icon_names,
+                                size,
+                                scale,
+                                flags & ~(GTK_ICON_LOOKUP_FORCE_REGULAR | GTK_ICON_LOOKUP_FORCE_SYMBOLIC));
+
+  if (new_names)
+    g_strfreev (new_names);
+
+  return icon_info;
+}
+
 
 /**
  * gtk_icon_theme_lookup_icon:
index 84bb0b6322912225febf401eba2b988e7de27e67..bdbaafe3172f44dc46a824f6882be5e4f1c97401 100644 (file)
@@ -113,6 +113,10 @@ struct _GtkIconThemeClass
  *   fallback, see gtk_icon_theme_choose_icon(). Since 2.12.
  * @GTK_ICON_LOOKUP_FORCE_SIZE: Always get the icon scaled to the
  *   requested size. Since 2.14.
+ * @GTK_ICON_LOOKUP_FORCE_REGULAR: Always load regular icons, even when
+ *   symbolic icon names are given. Since 3.14.
+ * @GTK_ICON_LOOKUP_FORCE_SYMBOLIC: Always load symbolic icons, even when
+ *   regular icon names are given. Since 3.14.
  * 
  * Used to specify options for gtk_icon_theme_lookup_icon()
  */
@@ -122,7 +126,9 @@ typedef enum
   GTK_ICON_LOOKUP_FORCE_SVG        = 1 << 1,
   GTK_ICON_LOOKUP_USE_BUILTIN      = 1 << 2,
   GTK_ICON_LOOKUP_GENERIC_FALLBACK = 1 << 3,
-  GTK_ICON_LOOKUP_FORCE_SIZE       = 1 << 4
+  GTK_ICON_LOOKUP_FORCE_SIZE       = 1 << 4,
+  GTK_ICON_LOOKUP_FORCE_REGULAR    = 1 << 5,
+  GTK_ICON_LOOKUP_FORCE_SYMBOLIC   = 1 << 6
 } GtkIconLookupFlags;
 
 /**